<%
layout("/layouts/platform.html"){
%>
    <header class="header navbar bg-white shadow">
		<div class="btn-group tool-button" style="padding:8px 0">
			<table>
           		<tbody>
           			<tr>
           				<td>
                       		<select id="state" name="state" class="form-control">
                       			<option value="">---全部---</option>
                       			<option value="0">---未支付---</option>
                       			<option value="1">---已支付---</option>
                       			<option value="2">---已退款---</option>
                       			<option value="3">---已作废---</option>
                       		</select>
                        </td>
                        <td>&nbsp;</td>
                  		<td>
                       		<input type="text" id="name" name="name" onclick="this.value=''" class="form-control" placeholder="姓名" autofocus>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                       		<input type="text" id="mobile" name="mobile" onclick="this.value=''" class="form-control" placeholder="电话" autofocus>
                        </td>
                        <td style="padding-left: 5px;">
                            <button id="searchBtn" type="button" class="btn btn-default"><i class="fa fa-search"></i>&nbsp;查询</button>
                      	</td>
                        </tr>
                    </tbody>
            </table>
		</div>
	</header>
    <div class="panel-body" style="padding-top: 70px;">
		<div class="box">
			<div class="box-body">
				<div class="col-sm-12">
					<div class="row">
           				<table class="table table-bordered table-hover mg-t datatable " style=" white-space: nowrap; text-overflow: ellipsis;">
			                <thead>
			                <tr>
			                    <th>姓名</th>
			                    <th>电话</th>
			                    <th>状态</th>
			                    <th>报名时间</th>
			                    <th>体检码</th>
			                    <th>订单号</th>
			                    <th>openId</th>
			                    <th>实际支付金额</th>
			                    <th>支付方式</th>
			                    <th>操作</th>
        	        	</table>
	    			</div>
				</div>
			</div>
		</div>
	</div>
<script language="JavaScript">
	var datatable;
	function initDatatable() {
	    datatable = $('.datatable').DataTable({
	        "dom": '<"toolbar">frtip',
	        "searching": false,
	        "processing": true,
	        "serverSide": true,
	        "select": true,
	        "ordering": false,
	        "scrollX": true,
	        "language": {
	            "url": "${base}/assets/plugins/datatables/cn.json"
	        },
	        "preDrawCallback": function () {
	            sublime.showLoadingbar($(".main-content"));
	        },
	        "drawCallback": function () {
	            sublime.closeLoadingbar($(".main-content"));
	        },
	        "ajax": {
	            "url": "${base}/platform/enroll/data",
	            "type": "post",
	            "data": function (d) {
	            	d.name = $('#name').val();
	            	d.mobile = $('#mobile').val();
	            	d.state = $('#state').val();
	            }
	        },
	        "order": [[0, "asc"]],
	        "columns": [
	            {"data": "name", "bSortable": true},
	            {"data": "mobile", "bSortable": true},
	            {"data": "state", "bSortable": true},
	            {"data": "enroll_time", "bSortable": true},
	            {"data": "id", "bSortable": true},
	            {"data": "bill_no", "bSortable": true},
	            {"data": "user_id", "bSortable": true},
	            {"data": "money", "bSortable": true},
	            {"data": "pay_way", "bSortable": true}
	        ],
	        "columnDefs": [
				{
					"render": function (data, type, row) {
						if(data==1){
							return "已支付";
						}else if(data==0){
							return "未支付";
						}else if(data==2){
							return "已退款";
						}else if(data==3){
							return "已作废 ";
						}
				     },
				     "targets": 2
				 },           
	         	 {
	            	"render": function (data, type, row) {
	                 	if (data) {
	                    	return moment(parseInt(data*1000)).format("YYYY-MM-DD HH:mm:ss");
	                    }
	                   return '';
	                 },
	                 "targets": 3
	             },
	             {
		            	"render": function (data, type, row) {
		                    return getPhysical(data);
		                 },
		                 "targets": 4
		             },
	             {
	           		"render": function (data, type, row) {
	           			var payState=row.pay_flag;
	           			var state=row.state;
	               		var html= '<div>';
	               		var id=row.id;
	                    if(payState && state==1){
	                    	html+='<a class="btn btn-xs btn btn-default " href="javascript:sendCode(\''+id+'\');">发送体检码</a>';
	                    }else if(payState && state==0){
	                    	html+='<a class="btn btn-xs btn btn-default " href="javascript:checkIsEnroll(\''+id+'\');">验证是否已交款</a>';
	                    }
	                    html+='</div>';
	                    return html;
	                    
	                     
	            	 },
	                 "targets": 9
	            }
	        ]
	    });
	    $("#searchBtn").on('click', function () {
	        datatable.ajax.reload();
	    });
	}
	$(function () {
	    initDatatable();
	});
	
	//发送体检码
	function sendCode(enrollid){
		$.post("${base}/platform/enroll/sendCode/" + enrollid, {}, function (data) {
            if (data.code == 0) {
            	Toast.success(data.msg);
                datatable.ajax.reload(null,false);
            } else {
                Toast.error(data.msg);
            }
        }, "json");
	}
	//验证是否已经支付
	function checkIsEnroll(enrollid){
		$.post("${base}/platform/enroll/checkIsEnroll/" + enrollid, {}, function (data) {
            if (data.code == 0) {
                Toast.success(data.msg);
            } else {
                Toast.error(data.msg);
            }
        }, "json");
	}
	
	function getPhysical(id){
    	var datas="";
    	$.ajax({
			url : "${base}/platform/enroll/getPhysical",
			data : {
				id : id
			},
			type : "post",
			async : false,
			dataType : "json",
			success : function(data){
				datas= data;
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				return false;
			}
		});
    	return datas;
    }
	
</script>
<%}%>
